<template>

	<div class="product-add">
		<el-tabs v-model="activeName" type="card">
			<el-tab-pane label="平台设置" name="plate"></el-tab-pane>
			<!-- <el-tab-pane label="商户设置" name="shop"></el-tab-pane> -->
			<el-tab-pane label="会员设置" name="user"></el-tab-pane>
		</el-tabs>
		<!--form表单-->
		<el-form size="small" ref="form" :model="form" label-width="150px">
			<!--平台设置-->
			<Plate v-show="activeName == 'plate'"></Plate>
			<!--商户设置-->
			<!-- <Shop v-show="activeName == 'shop'"></Shop> -->
			<!--会员设置-->
			<User v-show="activeName == 'user'"></User>
			<!--提交-->
			<div class="common-button-wrapper">
				<el-button type="primary" @click="onSubmit" :loading="loading">提交</el-button>
			</div>
		</el-form>
	</div>

</template>

<script>
	import {
		storeDetail,
		editStore
	} from "@/api/setting.js";
	import {
		formatModel
	} from '@/utils/base.js';
	import {
		useUserStore
	} from '@/store';
	const {
		changShop
	} = useUserStore();
	import Plate from './part/Plate.vue';
	import User from './part/User.vue';
	import Shop from './part/Shop.vue';
	const {
		changStore
	} = useUserStore();
	export default {
		components: {
			Plate,
			User,
			Shop
		},
		data() {
			return {
				activeName: 'plate',
				/*是否正在加载*/
				loading: false,
				/*form表单数据*/
				form: {
					name: "",
					customer: "",
					key: "",
					supplier_cash: "",
					operate_type: "",
					supplier_image: "",
					sms_open: "",
					supplier_logo: "",
					edit_audit: 1,
					add_audit: 1,
					is_get_log: 0,
					store_open: "",
					is_send_wx: 0,
					logoUrl: '',
					h5_sms_open: '',
					wx_open: '',
					wx_phone: '',
					mp_open: '',
					avatarUrl: '',
					tx_key: '',
					user_name: '',
					login_logo: '',
					login_desc: '',
					mp_phone: ''
				},
			};
		},
		provide: function() {
			return {
				form: this.form
			}
		},
		created() {
			this.getParams()
		},
		methods: {
			/*获取配置数据*/
			getParams() {
				let self = this;
				storeDetail({}, true)
					.then((res) => {
						let vars = res.data.vars.values;
						self.form = formatModel(self.form, vars);
						self.form.customer = vars.kuaidi100.customer;
						self.form.secret = vars.kuaidi100.secret;
						self.form.key = vars.kuaidi100.key;
						self.loading = false;
					})
					.catch((error) => {});
			},
			/*提交*/
			onSubmit() {
				let self = this;
				let params = this.form;
				self.$refs.form.validate((valid) => {
					if (valid) {
						self.loading = true;
						editStore(params, true)
							.then((data) => {
								self.loading = false;
								ElMessage({
									message: "恭喜你，商城设置成功",
									type: "success",
								});
								changShop(params.name);
								self.$router.push("/setting/store/index");
							})
							.catch((error) => {
								self.loading = false;
							});
					}
				});
			},
		}

	};
</script>
<style>
	.tips {
		color: #ccc;
	}

	input::-webkit-outer-spin-button,
	input::-webkit-inner-spin-button {
		-webkit-appearance: none;
	}

	input[type="number"] {
		-moz-appearance: textfield;
	}
</style>